﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;


namespace Tutorial1
{
  class Program
  {
    struct Person
    {
      public string firstName;
      public string lastName;
      public UInt16 age;
      public string email;
      public UInt32 phoneNumber;

      public Person(string fName, string lName, UInt16 h, string eM, UInt32 pNo)
      {
        this.firstName = fName;
        this.lastName = lName;
        this.age = h;
        this.email = eM;
        this.phoneNumber = pNo;
      }

      public override string ToString()
      {
        return (String.Format("First name:\t{0}\nLast name:\t{1}\nAge:\t\t{2}\nE-mail:\t\t{3}\nPhone number:\t{4}\n\n", firstName, lastName, age, email, phoneNumber));
      }

    }
    static void Main(string[] args)
    {

      int version = 5;

      switch(version)
      {
        case 0:
            int number = -1;

            while (!(number >= 0 && number <= 10))
            {
              Console.WriteLine("Please enter a number between 0 and 10:");
              number = int.Parse(Console.ReadLine());

              if (number >= 0 && number <= 10)
                Console.WriteLine("Good job!");

              else
                Console.WriteLine("Hey! The number should be 10 or less!");
            }
            break;
        case 1:
            bool badChoice = true;
            while (badChoice)
            {
              Console.WriteLine("Do you enjoy C# ? (yes/no/maybe)");
              string input = Console.ReadLine();
              switch (input.ToLower())
              {
                case "yes":
                case "maybe":
                  Console.WriteLine("Great!");
                  badChoice = false;
                  break;
                case "no":
                  Console.WriteLine("Too bad!");
                  badChoice = false;
                  break;
                default:
                  Console.WriteLine("I'm sorry, I don't understand that! Try Again..." + Environment.NewLine);
                  break;
              }
            }
            break;
        case 2:
            {
              {
                ArrayList list = new ArrayList();
                list.Add("John Doe");
                list.Add("Jane Doe");
                list.Add("Jane Doe");
                list.Add("Someone Else");
                list.Add("Someone Else");
                list.Add("John Doe");
                list.Add("Jane Doe");
                list.Add("Jane Doe");
                list.Add("Someone Else");
                list.Add("Someone Else");

                foreach (string name in list)
                  Console.WriteLine(name);

                Console.WriteLine("count: " + list.Count);
                Console.WriteLine("capacity: " + list.Capacity);
              }
              break;
            }
        case 3:
            {
              {
                ArrayList list = new ArrayList();
                list.Add(1);
                list.Add(2);
                list.Add(3);
                list.Add(4);
                list.Add(5);
                list.Add(6);
                list.Add(7);
                list.Add(8);
                list.Add(9);
                list.Add(10);

                foreach (int element in list)
                  Console.WriteLine(element);

                Console.WriteLine("count: " + list.Count);
                Console.WriteLine("capacity: " + list.Capacity);
                Console.WriteLine(list[0]+ Environment.NewLine);

                list.RemoveAt(0);
                list.Add(1);

                foreach (int element in list)
                  Console.WriteLine(element);

                Console.WriteLine("count: " + list.Count);
                Console.WriteLine("capacity: " + list.Capacity);

                Console.WriteLine(list[0]);
              }
              break;
            }
        case 4:
            {
              {
                List<Person> list = new List<Person>();

                Console.WriteLine("Capacity: {0}", list.Capacity);
                Console.WriteLine("Count: {0}", list.Count);

                using(StreamReader sReader = new StreamReader(File.OpenRead("test.txt")))
                while (!sReader.EndOfStream)
                {
                    string line = sReader.ReadLine();
                    var values = line.Split(';');
                    list.Add(new Person(values[0], values[1], Convert.ToUInt16(values[2]), values[3], Convert.ToUInt32(values[4])));
                }

                int count = 0;
                foreach (Person person in list)
                {
                  Console.WriteLine("Element #{0}:\n{1}", count, person);
                  count++;
                }

                Console.WriteLine("Capacity: {0}", list.Capacity);
                Console.WriteLine("Count: {0}", list.Count);

                using (StreamWriter sWriter = new StreamWriter("test2.txt"))
                  foreach (Person person in list)
                  {
                    sWriter.WriteLine(person.firstName + ';' + person.lastName + ';' + person.age + ';' + person.email + ';' + person.phoneNumber);
                  }


                //list.Add(new Person());
                //list[0].age = 10;
                //Console.WriteLine(list[0]);


                //foreach (Person person in list)
                //  Console.WriteLine(person);

                //Console.WriteLine("count: " + list.Count);
                //Console.WriteLine("capacity: " + list.Capacity);
              }
              break;
            }
        case 5:
            {
              int? zero = null;
              int x = 16;
              int y = 63;
              char? input = null;
              do
              {
                Console.Write("\nEnter key. Press \'Q\' or \'q\' to quit:");
                input = Char.ToLower(Console.ReadKey().KeyChar);
              }
              while (/*input != 'Q' && */input != 'q');
              string word = "fuckingFuck";
              Console.WriteLine(word);
              char[] wordArray = word.ToCharArray();
              if (char.IsLower(wordArray[0]))
                wordArray[0] = char.ToUpper(wordArray[0]);
              word = new string(wordArray);
              Console.WriteLine(word);
              Console.WriteLine();
              Console.WriteLine("x is: {0} and y is: {1}", x, y);
              x ^= y;
              y ^= x;
              x ^= y;
              Console.WriteLine("x is: {0} and y is: {1}", x, y);
              Console.WriteLine(zero == null);
              double radius = 6;
              double area = radius * radius * Math.PI;
              Console.WriteLine("Area of a circle with a radius of {0} is: {1}", radius, area);
              string[] languages = new string[]{
                "C#", "COBOL", "Java",
                "C++", "Visual Basic", "Pascal",
                "Fortran", "Lisp", "J#"
              };
              Console.WriteLine(languages.Length);
              foreach (string language in languages)
                Console.Write(language + " ");
              Array.Resize<string>(ref languages, 20);
              Console.WriteLine("\n" + languages.Length);
              foreach (string language in languages)
                Console.Write(language + " ");
              using (StringReader sR = new StringReader(languages[0]))
              {
                Console.WriteLine(Environment.NewLine + (char)sR.Peek());
              }
              break;
            }

      }

      Console.ReadLine();
    }

  }
}
